# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Arch Haskell Team <arch-haskell@haskell.org>

pkgname=agda-stdlib
pkgver=1.7.2
_agdaver=2.6.3
pkgrel=1
pkgdesc="Agda standard libraries"
url="https://github.com/agda/agda-stdlib"
license=("MIT")
arch=('loong64' 'x86_64')
depends=("agda=$_agdaver")
makedepends=('ghc' 'haskell-filemanip')
options=('staticlibs')
source=("$pkgname-$pkgver.tar.gz::https://github.com/agda/agda-stdlib/archive/v$pkgver.tar.gz"
        standard-library.agda-lib.in)
sha512sums=('518a7241df74bea217ebd80e753fdafaa05f5b4acf5e0df6202c8027dcd3906282335cfa5becf8484c9e06ef7eb335c7c3f1685e36106e229cca0551ba7748f2'
            '92fad2f9b941af4506bb0d5d9d533d09823df89f7530ee5d787b741816ba07e68f25b96d6653ae6ed949ec23484c1fba47a63cc6401311462a55b5e06cfc032c')

prepare() {
    cd $pkgname-$pkgver
    rm standard-library.agda-lib
}

build() {
    cd $pkgname-$pkgver

    runhaskell Setup configure -O --enable-shared --enable-executable-dynamic --disable-library-vanilla
    runhaskell Setup build $MAKEFLAGS

    dist/build/GenerateEverything/GenerateEverything

    agda -i. -isrc Everything.agda
}

package() {
    install -Dm644 standard-library.agda-lib.in "$pkgdir"/usr/share/agda/lib/standard-library.agda-lib

    cd $pkgname-$pkgver
    install -dm755 "$pkgdir"/usr/share/agda/lib/stdlib
    cp -pr src/* "$pkgdir"/usr/share/agda/lib/stdlib/

    # Symlink to avoid writing to this place when agda-lib is present
    install -dm755 "$pkgdir"/usr/share/agda/lib/_build/$_agdaver/agda
    ln -s ../../../stdlib "$pkgdir"/usr/share/agda/lib/_build/$_agdaver/agda/

    install -D -m644 LICENCE "$pkgdir"/usr/share/licenses/$pkgname/LICENCE
}
